package com.yjd.comm.news.model;

import java.lang.reflect.Field;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.util.HashMap;
import java.util.Map;

import com.yjd.comm.base.model.Model;
import com.yjd.comm.util.DateUtil;
import com.yjd.comm.util.StringUtil;

/**
 * <b>description</b>：新闻类模型<br>
 * <b>time</b>：2014-11-05 14:00:47 <br>
 * <b>author</b>： ready likun_557@163.com
 */
public class NewsModel extends Model {


	private Long id;
	//所属栏目id
	private Long catid;
	private String title;
	//来源
	private String from;
	//描述
	private String description;
	//排序
	private Integer pid;
	private Integer status;
	private Long inputtime;
	private Long updatetime;
	private String catName;
	private String inputtimeStr;
	private String updatetimeStr;
	private String shortTitle;
	private String contents;

	public String getContents() {
		return contents;
	}

	public void setContents(String contents) {
		this.contents = contents;
	}

	public void setInputtimeStr(String inputtimeStr) {
		this.inputtimeStr = inputtimeStr;
	}

	public void setUpdatetimeStr(String updatetimeStr) {
		this.updatetimeStr = updatetimeStr;
	}

	public String getInputtimeStr() {
		String str=inputtimeStr;
		if(StringUtil.isEmpty(inputtimeStr)){
			str=DateUtil.timestampToDateString(inputtime,"yyyy-MM-dd hh:mm:ss");
		}
		return str;
	}

	public String getUpdatetimeStr() {
		String str=updatetimeStr;
		if(StringUtil.isEmpty(updatetimeStr)){
			str=DateUtil.timestampToDateString(updatetime,"yyyy-MM-dd hh:mm:ss");
		}
		return str;
	}

	public String getCatName() {
		return catName;
	}

	public void setCatName(String catName) {
		this.catName = catName;
	}

	public Long getId() {
		return id;
	}

	public void setId(Long id) {
		this.id = id;
	}

	public Long getCatid() {
		return catid;
	}

	public void setCatid(Long catid) {
		this.catid = catid;
	}

	public String getTitle() {
		return title;
	}

	public void setTitle(String title) {
		this.title = title;
	}

	public String getFrom() {
		return from;
	}

	public void setFrom(String from) {
		this.from = from;
	}

	public String getDescription() {
		return description;
	}

	public void setDescription(String description) {
		this.description = description;
	}

	public Integer getPid() {
		return pid;
	}

	public void setPid(Integer pid) {
		this.pid = pid;
	}

	public Integer getStatus() {
		return status;
	}

	public void setStatus(Integer status) {
		this.status = status;
	}

	public Long getInputtime() {
		return inputtime;
	}

	public void setInputtime(Long inputtime) {
		this.inputtime = inputtime;
	}

	public Long getUpdatetime() {
		return updatetime;
	}

	public void setUpdatetime(Long updatetime) {
		this.updatetime = updatetime;
	}

	public Map getParamMap(NewsModel model) throws NoSuchMethodException,
			SecurityException, IllegalAccessException,
			IllegalArgumentException, InvocationTargetException {
		Map<String, Object> p = new HashMap<String, Object>();
		// 获取实体类的所有属性，返回Field数组
		Field[] field = model.getClass().getDeclaredFields();
		// 遍历所有属性
		for (int j = 0; j < field.length; j++) {
			// 获取属性的名字
			String name = field[j].getName();
			// 将属性的首字符大写，方便构造get，set方法
			name = name.substring(0, 1).toUpperCase() + name.substring(1);
			// 如果type是类类型，则前面包含"class "，后面跟类名
			Method m = model.getClass().getMethod("get" + name);
			// 调用getter方法获取属性值
			Object value =  m.invoke(model);
			if (value != null) {
				p.put(name, value);
			} 
		}
		return p;
	}

	public String getShortTitle() {
		return shortTitle;
	}

	public void setShortTitle(String shortTitle) {
		this.shortTitle = shortTitle;
	}

}
